package core.util.popup
{
	import core.util.ViewUtil;
	
	import flash.display.DisplayObject;
	
	import mx.core.IFlexDisplayObject;
	import mx.managers.PopUpManager;
	
	
	public class PopUpNormalWindow implements IPopUp
	{
		public function PopUpNormalWindow()
		{
		}
		
		private static var instance:PopUpNormalWindow;
		
		public static function Instance():PopUpNormalWindow
		{
			if (instance == null)
			{
				instance = new PopUpNormalWindow();
			}
			
			return instance;
		}
						
		private var array:Array = new Array();		//窗口集合		
				
	 	public function open(window:IFlexDisplayObject, model:Boolean = false):void		//目前只用到2个参数
		{
			array.push({'win':window,'mod':model});							
			var app:DisplayObject = ViewUtil.getInstance().mainStage as DisplayObject;//Application.application as DisplayObject;			
			PopUpManager.addPopUp(window, app, model);
			PopUpManager.centerPopUp(window);			
		}
		
		public function close():void
		{
			if (array.length == 0)
			{
				return;
			}
			
			var obj:Object = array.pop(); 			
			PopUpManager.removePopUp(obj['win'] as IFlexDisplayObject);			
		}
		
		public function closeAll():void
		{
			var len:int = array.length;
			while(len > 0)
			{
				close();
				len--;
			}
		}
	}
}